import { defineStore } from 'pinia'
import { fetchSysConfig } from '@/service/public'

export default defineStore('system', {
  state: () => ({
    bgmContext: uni.createInnerAudioContext(),
    config: null as any,
    classId: '',
    campsId: '0',
    sn: '',
    playerName: '',
  }),
  getters: {},
  actions: {
    getSysConfig(callback?: (data: any) => void) {
      fetchSysConfig({
        grade_id: this.classId,
      }).then((res) => {
        this.config = res.data
        callback && callback(res.data)
      })
    },
    setPlayer(v: string, name: string) {
      this.sn = v
      this.playerName = name
    },
    setClassId(id: string) {
      this.classId = id
    },
    setCampsId(id: string) {
      this.campsId = id
    },
  },
  persist: {
    paths: ['config', 'classId', 'sn', 'playerName'],
  },
})
